<template>
  <el-dialog @close="shbjdCancel('shbjdRuleForm')" :close-on-click-modal="false" title="审核造价单"
    :visible.sync="shbjdVisible" width="900px">
    <div class="scroll-view">
      <el-descriptions :column="2" border>
        <el-descriptions-item label="预计开工日期" v-if="fieldShowFunc('start_date')">{{ hisQuotationData.start_date || '--' }}</el-descriptions-item>
        <el-descriptions-item label="预计完工日期" v-if="fieldShowFunc('end_date')">{{ hisQuotationData.end_date || '--' }}</el-descriptions-item>
        <el-descriptions-item label="预计工期" v-if="fieldShowFunc('duration_days')">{{
          hisQuotationData.duration_days ? hisQuotationData.duration_days + '天' : '--' }}</el-descriptions-item>
        <el-descriptions-item label="建筑面积" v-if="fieldShowFunc('building_area')">{{ hisQuotationData.building_area ? hisQuotationData.building_area +
          'm²' : '--'
          }}</el-descriptions-item>
        <el-descriptions-item label="基础装修费" v-if="fieldShowFunc('basic_decoration_fee')">{{
          hisQuotationData.basic_decoration_fee ? hisQuotationData.basic_decoration_fee + '元' : '--'
        }}</el-descriptions-item>
        <el-descriptions-item label="主材采购费用" v-if="fieldShowFunc('material_costs')">{{ hisQuotationData.material_costs ? hisQuotationData.material_costs + '元'
          : '--'
          }}</el-descriptions-item>
        <el-descriptions-item label="报价税金" v-if="fieldShowFunc('quotation_taxes')">{{ hisQuotationData.quotation_taxes ? hisQuotationData.quotation_taxes + '元'
          :
          '--'
          }}</el-descriptions-item>
        <el-descriptions-item label="现场采购成本" v-if="fieldShowFunc('procurement_cost')">{{ hisQuotationData.procurement_cost ? hisQuotationData.procurement_cost +
          '元' : '--'
          }}</el-descriptions-item>
        <el-descriptions-item label="公司集采成本" v-if="fieldShowFunc('centralized_procurement_cost')">{{ hisQuotationData.centralized_procurement_cost ?
          hisQuotationData.centralized_procurement_cost + '元' :
          '--'
          }}</el-descriptions-item>
        <el-descriptions-item label="管理成本" v-if="fieldShowFunc('management_costs')">{{ hisQuotationData.management_costs ?
          hisQuotationData.management_costs + '元' :
          '--'
          }}</el-descriptions-item>
        <el-descriptions-item label="报价金额" v-if="fieldShowFunc('quotation_amount')">{{ hisQuotationData.quotation_amount ?
          hisQuotationData.quotation_amount + '元' :
          '--'
          }}</el-descriptions-item>
        <el-descriptions-item label="成本金额" v-if="fieldShowFunc('cost_amount')">{{ hisQuotationData.cost_amount ?
          hisQuotationData.cost_amount + '元' :
          '--'
          }}</el-descriptions-item>
        <el-descriptions-item label="利润金额" v-if="fieldShowFunc('profit_amount')">{{ hisQuotationData.profit_amount ?
          hisQuotationData.profit_amount + '元' :
          '--'
          }}</el-descriptions-item>
        <el-descriptions-item label="利润率(报价)" v-if="fieldShowFunc('bj_profit_amount')">{{ hisQuotationData.profit_ratio ?
          hisQuotationData.profit_ratio + '%' :
          '--'
          }}</el-descriptions-item>
        <el-descriptions-item label="报价类型" v-if="fieldShowFunc('bj_quotation_type')">
          <template v-if="hisQuotationData.quotation_type == 1">基础施工报价（首次）</template>
          <template v-if="hisQuotationData.quotation_type == 2">基础施工报价（调整）</template>
          <template v-if="hisQuotationData.quotation_type == 3">增减项施工报价</template>
        </el-descriptions-item>
        <el-descriptions-item label="备注" v-if="hisQuotationData.remark">{{ hisQuotationData.remark || '--' }}</el-descriptions-item>
        <el-descriptions-item label="报价单文件" :span="2" v-if="fieldShowFunc('quotation_file')">
          <div class="flex ac fw">
            <div @click="$fileViewHandle(item)" class="file-name"
              v-for="(item, index) in hisQuotationData.quotation_file" :key="index">{{ item.file_name }}</div>
          </div>
        </el-descriptions-item>
        <el-descriptions-item label="利润单文件" :span="2" v-if="fieldShowFunc('profit_statement_file')">
          <div class="flex ac fw">
            <div @click="$fileViewHandle(item)" class="file-name"
              v-for="(item, index) in hisQuotationData.profit_statement_file" :key="index">{{ item.file_name }}</div>
          </div>
        </el-descriptions-item>
        <el-descriptions-item label="成本单文件" :span="2" v-if="fieldShowFunc('cost_list_file')">
          <div class="flex ac fw">
            <div @click="$fileViewHandle(item)" class="file-name"
              v-for="(item, index) in hisQuotationData.cost_list_file" :key="index">{{ item.file_name }}</div>
          </div>
        </el-descriptions-item>
      </el-descriptions>
      <el-form :model="shbjdRuleForm" :rules="shbjdRules" ref="shbjdRuleForm" label-position="top">
        <el-form-item label="" prop="reviewPassed">
          <el-radio-group v-model="shbjdRuleForm.reviewPassed" size="small">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="2">拒绝</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input :rows="4" class="input-box" v-model="shbjdRuleForm.remark" type="textarea"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer">
      <el-button @click="shbjdCancel('shbjdRuleForm')">关闭</el-button>
      <el-button type="primary" @click="shbjdSubmit('shbjdRuleForm')" :disabled="diaLoading" :loading="diaLoading">确
        定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import projectApi from "@/api/projectApi";
import companyApi from "@/api/companyApi";
import adminApi from "@/api/adminApi";
import { getUserInfo } from "@/utils/auth";
import foremanApi from "@/api/foremanApi";

export default {
  name: "",
  props: {
    addDialogVisible: {
      type: Boolean,
      default: false,
      required: false,
    },
    project_id: {
      required: false,
    },
    hisQuotationData: {
      required: false,
    },
    fieldList:{
      required: false,
    }
  },
  data() {
    return {
      shbjdVisible: false,
      shbjdRules: {},
      shbjdRuleForm: {
        remark: "",
        quotation_id: "",
        reviewPassed: 1,
      },
      diaLoading: false,
    };
  },
  watch: {
    addDialogVisible(val1, val2) {
      console.log(this.hisQuotationData, '造价数据')
      this.shbjdVisible = this.addDialogVisible;
    },
  },

  computed: {},
  mounted() { },
  methods: {
    // 判断是否显示
    fieldShowFunc(field) {
      let fieldList = this.fieldList;
      return fieldList[field] == undefined ? true : fieldList[field];
    },
    // 审核报价单
    shbjdCancel(formName) {
      this.shbjdRuleForm = {
        remark: "",
        quotation_id: "",
        reviewPassed: 1,
      };
      this.$nextTick(() => {
        this.$refs[formName].clearValidate();
        this.$emit("onClose", true);
      });
    },
    shbjdSubmit(formName) {
      let shbjdRuleForm = this.shbjdRuleForm;
      console.log(shbjdRuleForm, "审核报价单参数");
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.diaLoading = true;
          // 拒绝
          if (shbjdRuleForm.reviewPassed == 2) {
            projectApi
              .quotationReviewRejected({
                quotation_id: "",
                project_id: this.project_id,
                remark: shbjdRuleForm.remark,
              })
              .then((res) => {
                console.log(res, "审核报价单");
                this.diaLoading = false;
                if (res.code == 200) {
                  this.$emit("onSuccess", true);
                }
                this.$message({
                  type: res.code == 200 ? "success" : "warning",
                  message: res.code == 200 ? "处理成功" : res.message,
                });
              })
              .catch((err) => {
                this.diaLoading = false;
                this.$message({
                  type: "warning",
                  message: err.message,
                });
              });
            return;
          }
          // 通过
          projectApi
            .quotationReviewPassed({
              quotation_id: "",
              project_id: this.project_id,
              remark: shbjdRuleForm.remark,
            })
            .then((res) => {
              console.log(res, "审核报价单");
              this.diaLoading = false;
              if (res.code == 200) {
                this.$emit("onSuccess", true);
              }
              this.$message({
                type: res.code == 200 ? "success" : "warning",
                message: res.code == 200 ? "处理成功" : res.message,
              });
            })
            .catch((err) => {
              this.diaLoading = false;
              this.$message({
                type: "warning",
                message: err.message,
              });
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "./index.scss";
</style>